package Thread;

public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1=new Thread(()->{
            for (int i = 0; i < 3; i++) {
                System.out.println("hello thread1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程Thread1结束");
        });
        Thread thread2=new Thread(()->{
            try {
                thread1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            for (int i = 0; i < 4; i++) {
                System.out.println("hello thread2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程Thread2结束");
        });
        thread1.start();
        thread2.start();
        System.out.println("main开始等待");
        thread1.join();
        thread2.join();
        System.out.println("main等待结束");
    }
}
